//window.onerror=function()
//{
//  return true;
//};

document.onselectstart=function() {
	var the = event.srcElement ; 
	if( ( the.tagName== "INPUT" && the.type.toLowerCase() == "text" ) || the.tagName== "TEXTAREA" ) 
	{ 
		return true; 
	} 
	
	return false ;
};

/*------------------- Utils ------------------------------*/ 

Utils = { 
/** 
* 判断各种浏览器类型 
*/ 
isOpera : navigator.userAgent.toLowerCase().indexOf("opera") > -1, 
isSafari : (/webkit|khtml/).test(navigator.userAgent.toLowerCase()), 
isIE : !this.isOpera && navigator.userAgent.toLowerCase().indexOf("msie") > -1, 
isIE7 : !this.isOpera && navigator.userAgent.toLowerCase().indexOf("msie 7") > -1, 
isGecko : !this.isSafari && navigator.userAgent.toLowerCase().indexOf("gecko") > -1, 

/** 
* 在给定的URL后加上时间搓，防止页面没有重新加载，而是使用缓存的页面 
*/ 
getUncacheUrl : function(url){ 
if(url == null) 
return null; 

if(url.indexOf("?") != -1) 
url += "&" + (new Date()).getTime(); 
else 
url += "?" + (new Date()).getTime(); 

return url; 
} 

}//ended Utils 

/*------------------- ProcessingHint ------------------------------*/ 

ProcessingHint = { 
	_loadingId : "ext-loadingStyle", 

	showProcessing : function(){ 
		document.write('<div class="ext-el-mask-msg x-mask-loading" id="'+this._loadingId+'" style="LEFT: '+parseInt(document.documentElement.clientWidth/2 - 120 )+'px; TOP: '+parseInt(document.documentElement.clientHeight/2)+'px">' + 
		' <div>' +
		' 页面正在加载中，请稍候.....' + 
		'     </div>' + 
		'    </div>'); 
	}, 

	close : function(){ 
		var loading = document.getElementById(this._loadingId); 
		if( loading )
			document.body.removeChild(loading); 
	} 
}//ended ProcessingHint 

/*------------------- DomReadyUtil ------------------------------*/ 

DomReadyUtil = { 
    docReadyState : false, 
    docReadyProcId : null, 

    fireDocReady : function(){ 

        if(this.docReadyState) 
            return; 

        this.docReadyState = true; 
        
        ProcessingHint.close(); 
        
        if(this.docReadyProcId){        
		    clearInterval(this.docReadyProcId); 
        } 
        
        if(Utils.isGecko || Utils.isOpera) { 
		    document.removeEventListener("DOMContentLoaded", this.fireDocReady, false); 
        } 
        
        if(Utils.isIE){ 
		    var defer = document.getElementById("ie-dom-ready-deferred-loader"); 
		    if(defer){ 
			    defer.onreadystatechange = null; 
			    defer.parentNode.removeChild(defer); 
		    } 
        } 
    }, 

    /** 
    * 初始化document文档 
    */ 
    initDocReady : function(){ 

	    this.docReadyState =false; 
	    this.docReadyProcId = null; 

	    ProcessingHint.showProcessing(); 

	    if(Utils.isGecko || Utils.isOpera) { 
		    document.addEventListener("DOMContentLoaded", this.fireDocReady, false); 
	    }
	    else if(Utils.isIE){ 
            document.write("<s"+'cript id="ie-dom-ready-deferred-loader" defer="defer" src="/'+'/:"></s'+"cript>"); 
            var defer = document.getElementById("ie-dom-ready-deferred-loader"); 
            defer.onreadystatechange = function(){ 
                if(this.readyState == "complete"){ 
                    DomReadyUtil.fireDocReady(); 
                } 
            }; 
        }else if(Utils.isSafari){ 
            docReadyProcId = setInterval(function(){ 
                var rs = document.readyState; 
                if(rs == "complete") { 
                    DomReadyUtil.fireDocReady(); 
                 } 
            }, 10); 
        } 
    } 
}//ended DomReadyUtil 

DomReadyUtil.initDocReady();

//------------------------------ 列表选择操作方法 ----------------------------------
function addID(id) {
    if (form1.hdSelect.value.length == 0) {
        form1.hdSelect.value = id;
    }
    else {
        form1.hdSelect.value = form1.hdSelect.value + "," + id;
    }
}

function doCheckAll() {
    var chk = form1.chkAll.checked;
    var e;
    for (var i = 0; i < form1.elements.length; i++) {
        e = form1.elements[i];
        if (e.type == "checkbox") {
            if (e.name.substring(0, 4) == "chk_") {
                e.checked = chk;
            }
        }
    }
}

function changeCheckbox(bolChecked) {
    var e;
    for (var i = 0; i < form1.elements.length; i++) {
        e = form1.elements[i];
        if (e.type == "checkbox") {
            e.checked = bolChecked;
        }
    }
}

function doCheckSingle(id) {
    var e = document.getElementById("chk_" + id);

    if (!e.checked) {
        form1.chkAll.checked = false;
    }
}

function checkSelect() 
{
	var e;
	// 先清除之前数据
	form1.hdSelect.value = "";
	
	for (var i = 0; i < form1.elements.length; i++) 
	{
		e = form1.elements[i];
		if (e.type == "checkbox") 
		{
			if (e.name.substring(0, 4) == "chk_") 
			{
				if (e.checked) 
				{
					addID(e.name.substring(4, e.name.length));
				}
			}
		}
	}	
}

//------------------------------ END 列表选择操作方法 ----------------------------------

//编写人   : 王超
//编写日期 : 2007-05-14
//方法作用 : 获取Url参数
function GetParamValue(ParamName){
    var Url=window.location.href;//如果想获取框架顶部的url可以用 top.window.location.href


    var u,g,StrBack='';
    if(arguments[arguments.length-1]=="#")
       u=Url.split("#");
    else
       u=Url.split("?");

    if (u.length==1) g='';
    else g=u[1];

    if(g!=''){
       gg=g.split("&");
       var MaxI=gg.length;
       for(xm=0;xm<MaxI;xm++){
          if(gg[xm].indexOf(ParamName)==0) {
		    ParamName=ParamName+"=";
            StrBack=gg[xm].replace(ParamName,"");
		    //document.write("<br>"+StrBack);
            break;
          }
       }
    }
    return StrBack;
}

//------------------------------ Start 遮罩效果 ----------------------------------
function createMaskDiv()
{
    var shadow = document.createElement("div");
    shadow.setAttribute("id","shadow");
    shadow.style.zIndex="10";

    var box=document.createElement("div");
    box.setAttribute("id","box");
    box.setAttribute("background","#000 url("+projectroot+"Resource/Images/load.gif) no-repeat center center;");
    box.style.zIndex="999";
    
    var divContent=document.createElement("div");
    divContent.innerHTML="<p id=\"loading-one\" >正在处理你的请求,请不要刷新,请稍候...</p>";

    box.appendChild(divContent);

    document.body.appendChild(shadow);
    document.body.appendChild(box);
}

function hideMaskDiv()
{
    var box=document.getElementById("box");
    var shadow=document.getElementById("shadow");
    
    if( box )
		document.body.removeChild(box);
	if( shadow )
		document.body.removeChild(shadow);
}
//------------------------------ End 遮罩效果 ----------------------------------

//禁用回退和刷新功能
document.onkeydown = function(){
	if ((window.event.altKey) &&
      ((window.event.keyCode == 37) ||
       (window.event.keyCode == 39))) {
        alert("不准您使用ALT+方向鍵前进或后退网页！");
        event.returnValue = false;
    }
    if ((event.keyCode == 116) ||
      (event.keyCode == 112) ||
      (event.ctrlKey && event.keyCode == 82)) {
        event.keyCode = 0;
        event.returnValue = false;
    }
    if (event.keyCode == 122) { event.keyCode = 0; event.returnValue = false; }
    if ((event.ctrlKey) && (event.keyCode == 78))
        event.returnValue = false;
    if ((event.shiftKey) && (event.keyCode == 121))
        event.returnValue = false;
    if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
        window.event.returnValue = false;
    if ((window.event.altKey) && (window.event.keyCode == 115)) {
        window.showModelessDialog("about:blank", "", "dialogWidth:1px;dialogheight:1px");
        return false;
    }
	
	if (((event.keyCode == 8) &&                                                    //BackSpace 
		 ((event.srcElement.type != "text" && 
		 event.srcElement.type != "textarea" && 
		 event.srcElement.type != "password") || 
		 event.srcElement.readOnly == true)) || 
		((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||    //CtrlN,CtrlR 
		(event.keyCode == 116) ) {                                                   //F5 
		event.keyCode = 0; 
		event.returnValue = false; 
	}
}

function getCookie( cookie , cookieName) {   
	var cookieString;
	
	if( cookie != "" )
		cookieString = cookie;   
	else
		cookieString = document.cookie;
	
	var start = cookieString.indexOf(cookieName + '=');   
	// 加上等号的原因是避免在某些 Cookie 的值里有   
	// 与 cookieName 一样的字符串。   
	if (start == -1) // 找不到   
	return null;   
	start += cookieName.length + 1;   
	var end = cookieString.indexOf(';', start);   
	if (end == -1) return unescape(cookieString.substring(start));   
	return unescape(cookieString.substring(start, end));   
} 

function pointerX() {
	return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
}

function pointerY() {
	return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
}

function ShowInfo(title,msg) {
	$.messager.alert(title, msg,'info');
}
function ShowError(title,msg) {
	$.messager.alert(title, msg, 'error');
}
function ShowQuestion(title,msg) {
	$.messager.alert(title, msg, 'question');
}
function ShowInfoAndRedirect(title,msg,url) {
	$.messager.alert(title, msg,'info',function(){
		location.replace(url);
	});	
}
function ShowErrorAndRedirect(title,msg,url) {
	$.messager.alert(title, msg, 'error',function(){
		location.replace(url);
	});	
}

//这个可以验证15位和18位的身份证，并且包含生日和校验位的验证。
//如果有兴趣，还可以加上身份证所在地的验证，就是前6位有些数字合法有些数字不合法。
function isIdCardNo(num)
{
    num = num.toUpperCase();
    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。
    if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num)))
    {
        alert('输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。');
        return false;
    }
    
    //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
    //下面分别分析出生日期和校验位
    var len, re;
    len = num.length;
    if (len == 15)
    {
        re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
        var arrSplit = num.match(re);
        //检查生日日期是否正确
        var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay)
        {
            alert('输入的身份证号里出生日期不对！');
            return false;
        }
        else
        {
            //将15位身份证转成18位
            //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
            var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            var nTemp = 0, i;
            num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
            for(i = 0; i < 17; i ++)
            {
                nTemp += num.substr(i, 1) * arrInt[i];
            }
            num += arrCh[nTemp % 11];
            return num;
        }
    }
    if (len == 18)
    {
        re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
        var arrSplit = num.match(re);
        //检查生日日期是否正确
        var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay)
        {
            alert(dtmBirth.getYear());
            alert(arrSplit[2]);
            alert('输入的身份证号里出生日期不对！');
            return false;
        }
        else
        {
            //检验18位身份证的校验码是否正确。
            //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
            var valnum;
            var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
            var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
            var nTemp = 0, i;
            for(i = 0; i < 17; i ++)
            {
                nTemp += num.substr(i, 1) * arrInt[i];
            }
            valnum = arrCh[nTemp % 11];
            if (valnum != num.substr(17, 1))
            {
                alert('18位身份证的校验码不正确！应该为：' + valnum);
                return false;
            }
            return num;
        }
    }
    return false;
}